package com.qy.mgr;

import java.util.HashMap;
import java.util.List;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.qy.DaoMgr;
import com.qy.bean.CheckStation;
import com.qy.util.MathUtil;
import com.qy.util.StaticData;

public class CheckStationMgr {
	public static HashMap<Integer, CheckStation> map = new HashMap<Integer, CheckStation>();
	
	/**
	 * 初始化系统商店
	 * @return
	 */
	public static boolean init(){
		List<CheckStation> list = DaoMgr.getCheckStationDao().getCheckStationList();
		for(CheckStation tmp:list){
			map.put(tmp.getId(), tmp);
		}
		return true;
	}
	
	/**
	 * 获取车间站信息
	 * @param id
	 * @return
	 */
	public static CheckStation getCheckStation(int id){
	    return map.get(id);
	}
	
	/**
	 * 获取车间站的信息
	 * id,图片，名称，位置，车检员工号
	 * @return
	 */
	public static JSONArray getCheckStationList(){
		JSONArray jsa = new JSONArray();
		JSONObject js = null;
		for(CheckStation tmp:map.values()){
			js = new JSONObject();
			js.put("id", tmp.getId());
			js.put("image", tmp.getPoint());
			js.put("name", tmp.getName());
			js.put("sellPrice", tmp.getServerId());
			jsa.add(js);
		}
		return jsa;
	}
	
	/**
	 * 
	 *获取离当前点最近的车检站
	 * @param point
	 * @return
	 */
	public static int getNearest(String point){
	    int stationId = StaticData.no_param;
	    double distance = StaticData.no_param;
	    double dTmp = StaticData.no_param;
	    for(CheckStation tmp:map.values()){
		dTmp = MathUtil.GetDistance(point, tmp.getPoint());
		if(distance==StaticData.no_param||dTmp<distance){
		    distance = dTmp;
		    stationId = tmp.getId();
		}
	    }
	    return stationId;
	}
}
